﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using CourseSystem.Core.Entities;
using CourseSystem.Core.SqlServerDAL;

namespace CourseSystem.Core.BLL
{
    public class SubjectBLL
    {
        public static IQueryable<SubjectInfo> GetList(int id)
        {
            using (var dal = new SubjectDAL(Settings.ConnectionName))
            {
                var re = dal.SelectQueryable(o => o.CollegeId == id);
                return re;
            }
        }

        public static SubjectInfo Get(int id)
        {
            using (var dal = new SubjectDAL(Settings.ConnectionName))
            {
                var re = dal.SelectSingle(o => o.Id == id);
                return re;
            }
        }

        public static List<SubjectInfo> GetByColId(int id)
        {
            using (var dal = new SubjectDAL(Settings.ConnectionName))
            {
                var re = dal.Select(o => o.CollegeId == id);
                return re;
            }
        }

        public static bool IsExist(Expression<Func<SubjectInfo, bool>> expression)
        {
            using (var dal = new SubjectDAL(Settings.ConnectionName))
            {
                return dal.SelectSingle(expression) != null;
            }
        }

        public static bool Edit(SubjectInfo info)
        {
            using (var dal = new SubjectDAL(Settings.ConnectionName))
            {
                return dal.Update(info) != null;
            }
        }

        public static bool Add(SubjectInfo info)
        {
            using (var dal = new SubjectDAL(Settings.ConnectionName))
            {
                return dal.Add(info) != null;
            }
        }

        public static SubjectInfo Get(string collegeName,string subjectName)
        {
            using (var dal = new SubjectDAL(Settings.ConnectionName))
            {
                return dal.SelectSingle(o => o.Name == subjectName && o.CollegeInfo.Name == collegeName);
            }
        }

       
    }
}
